home *** CD-ROM | disk | FTP | other *** search
- #include <MacIncludes.h>
- #include "Rk.h"
- #include "Structs.h"
- #include "file+rk.h"
- #include "Offscreen.h"
- #include <CType.h>
-
- #define TopLeft(aRect) (* (Point *) &(aRect).top)
- #define BotRight(aRect) (* (Point *) &(aRect).bottom)
-
- #define PRED_CLIP 0
- #define TEXT_CLIP 1
-
- void AdjustCursor (Point mouse, RgnHandle region );
- void AdjustCurPred(Point mouse, RgnHandle region, WindowPtr window);
- void AdjustCurText(Point mouse, RgnHandle region, WindowPtr window);
-
-
- extern void SpecialLine(char *line,char *prediction);
-
-
- extern Boolean gInBackground; /* maintained by Initialize and DoEvent */
- extern WindowPtr gPredict,gText;
- extern short gContextBar;
- extern FontInfo gFInfo,gNormFInfo;
- extern GrafPort goffScreen;
- extern Ptr Hilite;
- extern int gSelLine, gSelChar;
- extern Rect gHiliteRect;
- extern int pred_number;
- extern short gPredScrollNum;
- extern Boolean gNewLine;
- extern pascal void nullEraseRect(GrafVerb verb,const Rect *r);
-
-
-
-
- #pragma segment Main2
- void AdjustCursor(Point mouse,RgnHandle region)
- {
- WindowPtr window;
-
-
- window = FrontWindow(); /* we only adjust the cursor when we are in front */
- if ( (! gInBackground) && (! IsDAWindow(window)) ) {
- if(window==gText){
- AdjustCurText(mouse, region, window);
- } else if(window==gPredict){
- AdjustCurPred(mouse, region, window);
- }else
- SetCursor(&qd.arrow);
- }
- } /* AdjustCursor */
-
- void AdjustCurPred(Point mouse,RgnHandle region, WindowPtr window)
- {
- RgnHandle arrowRgn;
- RgnHandle iBeamRgn;
- RgnHandle MoveRgn;
- RgnHandle CharRgn;
- Rect Clip;
- Rect MoveRect;
- Rect CharRect;
- Rect ContextRect;
- Rect iBeamRect;
- Rect TextRect;
- Rect globalRect;
- char prediction[100];
- char line[100];
- char buffer[100];
- int Count;
- CharsHandle TEText;
- TEHandle te;
- Boolean drawNeeded;
- BitMapPtr backMap,selectMap;
- GrafPort store= *window;
-
-
- te = ((DocumentPeek) gText)->docTE;
-
- /* calculate regions for different cursor shapes */
- arrowRgn = NewRgn();
- iBeamRgn = NewRgn();
- MoveRgn = NewRgn();
- CharRgn = NewRgn();
-
- /* start arrowRgn wide open */
- SetRectRgn(arrowRgn, kExtremeNeg, kExtremeNeg, kExtremePos, kExtremePos);
-
- SetRect(&MoveRect,gContextBar-1,
- 0,
- gContextBar+2,
- gPredict->portRect.bottom-gPredict->portRect.top-16);
- iBeamRect=gPredict->portRect;
- iBeamRect.bottom=((gPredict->portRect.bottom-20)/
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading))
- *(gFInfo.ascent+gFInfo.descent+gFInfo.leading);
- iBeamRect.right-=16;
-
-
- SetPort(window);
-
- LocalToGlobal(&TopLeft(MoveRect));
- LocalToGlobal(&BotRight(MoveRect));
- LocalToGlobal(&TopLeft(iBeamRect));
- LocalToGlobal(&BotRight(iBeamRect));
-
- RectRgn(MoveRgn, &MoveRect);
- RectRgn(iBeamRgn, &iBeamRect);
-
- /* we temporarily change the port╒s origin to ╥globalfy╙ the visRgn */
- /* SetOrigin(-window->portBits.bounds.left, -window->portBits.bounds.top);
- SectRgn(MoveRgn, window->visRgn, MoveRgn);
- SectRgn(iBeamRgn, window->visRgn, iBeamRgn);
- SetOrigin(0, 0);
- */
- /* subtract other regions from arrowRgn */
- DiffRgn(arrowRgn, MoveRgn, arrowRgn);
- DiffRgn(arrowRgn, iBeamRgn, arrowRgn);
-
-
- /* change the cursor and the region parameter */
- if ( PtInRgn(mouse, MoveRgn ) ) {
- SetCursor(*GetCursor(rMoveBarCursor));
- CopyRgn(MoveRgn, region);
- UpdateContext(te);
- } else if ( PtInRgn(mouse, iBeamRgn) ){
- SetPort(gPredict);
- PushClip(PRED_CLIP);
- SetRect(&Clip,window->portRect.left,window->portRect.top,window->portRect.right-15, window->portRect.bottom-15);
- ClipRect(&Clip);
-
- GlobalToLocal(&mouse);
- if(mouse.h>=gContextBar){
- GetGlobalRect(gPredict,&globalRect);
- if(CheckBoundsOffscreen(((OffscreenPeek)window)->fBackHandle,&globalRect, &drawNeeded)) debugstr("No Memory in AdjustCurPred")/* Handle Memerr? */;
- if(drawNeeded){
- BeginOffscreenDrawing(((OffscreenPeek)window)->fBackHandle,window);
- EraseRect(&window->portRect);
- ReDrawPredictions();
- EndOffscreenDrawing(((OffscreenPeek)window)->fBackHandle);
- }
- backMap = GetMap(((OffscreenPeek)window)->fBackHandle);
- selectMap = GetMap(((OffscreenPeek)window)->fSelectHandle);
-
- if(backMap){
- ForeColor(blackColor);
- BackColor(whiteColor);
- if(selectMap){
- CopyBits(backMap, selectMap, &window->portRect, &window->portRect, srcCopy, nil);
- }
- ValidRectOffscreen(((OffscreenPeek)window)->fBackHandle, nil, &window->portRect);
- }
- pred_number=(mouse.v-2)/
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading)+gPredScrollNum;
- if (pred_number<0) pred_number=0;
- *window=store;
- SetPort(gPredict);
- SetRect(&Clip,window->portRect.left,window->portRect.top,window->portRect.right-15, window->portRect.bottom-15);
- ClipRect(&Clip);
- InvalRectOffscreen(((OffscreenPeek)window)->fSelectHandle,nil,&Clip);
- if(CheckBoundsOffscreen(((OffscreenPeek)window)->fSelectHandle,&globalRect, &drawNeeded)) debugstr("No Memory in AdjustCurPred");/* Handle Memerr? */;
- BeginOffscreenDrawing(((OffscreenPeek)window)->fSelectHandle,window);
- SetRect(&ContextRect,0,0,gContextBar,gPredict->portRect.bottom-18);
- EraseRect(&ContextRect);
- TEText=TEGetText(te);
- for(Count=(*te)->selStart;(Count>0)&&
- ((TextWidth((Ptr)(*TEText),Count,(*te)->selStart-Count))<(gContextBar-2))
- ;Count--);
- strncpy(buffer,((char *)*TEText)+Count,(*te)->selStart-Count);
- SpecialLine(buffer,buffer);
- if((*te)->selStart==0){
- MoveTo((gContextBar-2)-TextWidth("(NONE)",0,6),
- (pred_number-gPredScrollNum)*
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading)+4+(gFInfo.ascent));
- DrawString("\p(NONE)");
- }else{
- MoveTo((gContextBar-2)-TextWidth(buffer,0,
- (*te)->selStart-Count),
- (pred_number-gPredScrollNum)*
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading)+4+(gFInfo.ascent));
- DrawText(buffer,0,(*te)->selStart-Count);
- }
- make_a_prediction(prediction);
- SpecialLine(line,prediction);
- Count=1;
- while(((TextWidth(line,0,Count++)+gContextBar+5)<mouse.h)
- && *(line+Count-1));
-
- Count--;
- SetRect(&CharRect,
- TextWidth(line,0,Count-1)+gContextBar+5,
- (pred_number-gPredScrollNum)*(gFInfo.ascent+gFInfo.descent+gFInfo.leading)+2,
- TextWidth(line,0,Count)+gContextBar+5,
- (pred_number+1-gPredScrollNum)*(gFInfo.ascent+gFInfo.descent+gFInfo.leading)+2);
- gSelChar=Count;
-
- SetRect(&gHiliteRect,gContextBar+5,
- (pred_number-gPredScrollNum)*(gFInfo.ascent+gFInfo.descent+gFInfo.leading)+2,
- TextWidth(line,0,Count)+gContextBar+5,
- (pred_number+1-gPredScrollNum)*(gFInfo.ascent+gFInfo.descent+gFInfo.leading)+2);
-
- BitClr(Hilite,pHiliteBit);
- InvertRect(&gHiliteRect);
- EndOffscreenDrawing(((OffscreenPeek)window)->fSelectHandle);
- selectMap = GetMap(((OffscreenPeek)window)->fSelectHandle);
- if(selectMap){
- ForeColor(blackColor);
- BackColor(whiteColor);
- CopyBits(selectMap, &qd.thePort->portBits, &gPredict->portRect, &gPredict->portRect, srcCopy, nil);
- ValidRectOffscreen(((OffscreenPeek)window)->fSelectHandle,gPredict,&Clip);
- }
- if((*te)->teLength<=(*te)->selStart ) {
- QDProcs theprocs,*oldprocs;
- Rect BackRect;
- char line[100];
-
-
- SpecialLine(line,prediction);
-
- /* this is REALLY GROSS, but should be portable with no problem
- TextEdit does not update the selRect until you make TE calls
- so we call TEDelete and patch EraseRect so it doesn't refresh
- the window */
-
- SetPort(gText);
- SetStdProcs(&theprocs);
- theprocs.rectProc=(Ptr)nullEraseRect;
- oldprocs=gText->grafProcs;
- gText->grafProcs=&theprocs;
-
- TEDelete(((DocumentPeek)gText)->docTE);
- gText->grafProcs=oldprocs;
-
-
- SetRect(&TextRect,(*te)->selRect.left
- ,(*te)->selRect.top,
- (*te)->selRect.left+(goffScreen.portBits.bounds.right -
- goffScreen.portBits.bounds.left),
- (*te)->selRect.top+
- gNormFInfo.ascent+gNormFInfo.descent
- +gNormFInfo.leading);
- SetPort(&goffScreen);
- EraseRect(&goffScreen.portRect);
- BackRect=qd.thePort->portRect;
- BackRect.right=TextWidth(line,0,Count)+2;
- PaintRect(&BackRect);
- TextMode(srcBic);
- MoveTo(1,gNormFInfo.ascent+gNormFInfo.leading-1);
- DrawText(line,0,Count);
- SetPort(gText);
- PushClip(TEXT_CLIP);
- ClipRect(&(*te)->viewRect);
- CopyBits(&goffScreen.portBits,&qd.thePort->portBits,
- &goffScreen.portRect,&TextRect,srcCopy,NULL);
- PopClip(TEXT_CLIP);
- }
- SetPort(gPredict);
- LocalToGlobal(&TopLeft(CharRect));
- LocalToGlobal(&BotRight(CharRect));
- RectRgn(CharRgn, &CharRect);
- SetOrigin(-window->portBits.bounds.left, -window->portBits.bounds.top);
- SectRgn(CharRgn, window->visRgn, CharRgn);
- SetOrigin(0, 0);
- SetCursor(*GetCursor(iBeamCursor));
- CopyRgn(CharRgn, region);
- } else { /* reverse Select */
- SetRect(&TextRect,(*te)->selRect.left
- ,(*te)->selRect.top,
- (*te)->selRect.left+(goffScreen.portBits.bounds.right -
- goffScreen.portBits.bounds.left),
- (*te)->selRect.top+
- gNormFInfo.ascent+gNormFInfo.descent
- +gNormFInfo.leading);
- SetPort(gText);
- PushClip(TEXT_CLIP);
- ClipRect(&(*te)->viewRect);
- EraseRect(&TextRect);
- PopClip(TEXT_CLIP);
-
- GetGlobalRect(gPredict,&globalRect);
- if(CheckBoundsOffscreen(((OffscreenPeek)window)->fBackHandle,&globalRect, &drawNeeded)) debugstr("No Memory in AdjustCurPred")/* Handle Memerr? */;
- if(drawNeeded){
- BeginOffscreenDrawing(((OffscreenPeek)window)->fBackHandle,window);
- EraseRect(&window->portRect);
- ReDrawPredictions();
- EndOffscreenDrawing(((OffscreenPeek)window)->fBackHandle);
- }
- backMap = GetMap(((OffscreenPeek)window)->fBackHandle);
- selectMap = GetMap(((OffscreenPeek)window)->fSelectHandle);
-
- if(backMap){
- ForeColor(blackColor);
- BackColor(whiteColor);
- if(selectMap){
- CopyBits(backMap, selectMap, &window->portRect, &window->portRect, srcCopy, nil);
- }
- ValidRectOffscreen(((OffscreenPeek)window)->fBackHandle, nil, &window->portRect);
- }
- pred_number=(mouse.v-2)/
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading)+gPredScrollNum;
- if (pred_number<0) pred_number=0;
- *window=store;
- SetPort(gPredict);
- SetRect(&Clip,window->portRect.left,window->portRect.top,window->portRect.right-15, window->portRect.bottom-15);
- ClipRect(&Clip);
- InvalRectOffscreen(((OffscreenPeek)window)->fSelectHandle,nil,&Clip);
- if(CheckBoundsOffscreen(((OffscreenPeek)window)->fSelectHandle,&globalRect, &drawNeeded)) debugstr("No Memory in AdjustCurPred");/* Handle Memerr? */;
- BeginOffscreenDrawing(((OffscreenPeek)window)->fSelectHandle,window);
- SetRect(&ContextRect,0,0,gContextBar,gPredict->portRect.bottom-18);
- EraseRect(&ContextRect);
- if((*te)->selStart==0){
- MoveTo((gContextBar-2)-TextWidth("(NONE)",0,6),
- (pred_number-gPredScrollNum)*
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading)+4+(gFInfo.ascent));
- DrawString("\p(NONE)");
- }else{
- TEText=TEGetText(te);
- Count=(*te)->selStart - ((gContextBar-2)/CharWidth(' '));
- if(Count< 0 ) Count=0;
- strncpy(buffer,(Ptr) *TEText+Count, ((gContextBar-2)/CharWidth(' ')));
- SpecialLine(buffer,buffer);
- MoveTo((gContextBar-2)-(CharWidth(' ')*((*te)->selStart-Count)),
- (pred_number-gPredScrollNum)*
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading)+4+(gFInfo.ascent));
- DrawText(buffer,0,(*te)->selStart-Count);
- }
- Count=(*te)->selStart - (((gContextBar-2)-mouse.h)/CharWidth(' '));
- if(Count< 0 ) Count=0;
- SetRect(&CharRect,
- (gContextBar-2)-(CharWidth(' ')*(((gContextBar-2)-mouse.h)/CharWidth(' '))),
- (pred_number-gPredScrollNum)*(gFInfo.ascent+gFInfo.descent+gFInfo.leading)+2,
- (gContextBar-2)-(CharWidth(' ')*(((gContextBar-2)-mouse.h)/CharWidth(' ')))+1,
- (pred_number+1-gPredScrollNum)*(gFInfo.ascent+gFInfo.descent+gFInfo.leading)+2);
- gSelChar=Count;
-
- SetRect(&gHiliteRect,
- (gContextBar-2)-(CharWidth(' ')*((*te)->selStart - Count)),
- (pred_number-gPredScrollNum)*(gFInfo.ascent+gFInfo.descent+gFInfo.leading)+2,
- (gContextBar-2),
- (pred_number+1-gPredScrollNum)*(gFInfo.ascent+gFInfo.descent+gFInfo.leading)+2);
-
- BitClr(Hilite,pHiliteBit);
- InvertRect(&gHiliteRect);
- EndOffscreenDrawing(((OffscreenPeek)window)->fSelectHandle);
- selectMap = GetMap(((OffscreenPeek)window)->fSelectHandle);
- if(selectMap){
- ForeColor(blackColor);
- BackColor(whiteColor);
- CopyBits(selectMap, &qd.thePort->portBits, &gPredict->portRect, &gPredict->portRect, srcCopy, nil);
- ValidRectOffscreen(((OffscreenPeek)window)->fSelectHandle,gPredict,&Clip);
- }
- SetPort(gPredict);
- PopClip(PRED_CLIP);
- LocalToGlobal(&TopLeft(CharRect));
- LocalToGlobal(&BotRight(CharRect));
- RectRgn(CharRgn, &CharRect);
- SetOrigin(-window->portBits.bounds.left, -window->portBits.bounds.top);
- SectRgn(CharRgn, window->visRgn, CharRgn);
- SetOrigin(0, 0);
- SetCursor(*GetCursor(iBeamCursor));
- CopyRgn(CharRgn, region);
- }
- } else {
- SetCursor(&qd.arrow);
- CopyRgn(arrowRgn, region);
- UpdateContext(te);
- }
-
- DisposeRgn(arrowRgn);
- DisposeRgn(MoveRgn );
- DisposeRgn(iBeamRgn);
- DisposeRgn(CharRgn );
- *window=store;
- }
-
- void AdjustCurText(Point mouse, RgnHandle region, WindowPtr window)
- {
-
- Rect iBeamRect;
- RgnHandle arrowRgn;
- RgnHandle iBeamRgn;
-
- /* calculate regions for different cursor shapes */
- arrowRgn = NewRgn();
- iBeamRgn = NewRgn();
-
- /* start arrowRgn wide open */
- SetRectRgn(arrowRgn, kExtremeNeg, kExtremeNeg, kExtremePos, kExtremePos);
-
- /* calculate iBeamRgn */
- if ( IsAppWindow(window) ) {
- iBeamRect = (*((DocumentPeek) window)->docTE)->viewRect;
- SetPort(window); /* make a global version of the viewRect */
- LocalToGlobal(&TopLeft(iBeamRect));
- LocalToGlobal(&BotRight(iBeamRect));
- RectRgn(iBeamRgn, &iBeamRect);
- /* we temporarily change the port╒s origin to ╥globalfy╙ the visRgn */
- SetOrigin(-window->portBits.bounds.left, -window->portBits.bounds.top);
- SectRgn(iBeamRgn, window->visRgn, iBeamRgn);
- SetOrigin(0, 0);
- }
-
- /* subtract other regions from arrowRgn */
- DiffRgn(arrowRgn, iBeamRgn, arrowRgn);
-
- /* change the cursor and the region parameter */
- if ( PtInRgn(mouse, iBeamRgn) ) {
- SetCursor(*GetCursor(iBeamCursor));
- CopyRgn(iBeamRgn, region);
- } else {
- SetCursor(&qd.arrow);
- CopyRgn(arrowRgn, region);
- }
-
- DisposeRgn(arrowRgn);
- DisposeRgn(iBeamRgn);
- }
-
-
-
- UpdateContext(te)
- TEHandle te;
- {
- Rect globalRect;
- Boolean drawNeeded;
- BitMapPtr backMap,selectMap;
- Rect Clip;
- Rect TextRect;
-
- if((*te)->teLength<=(*te)->selStart){
- TEDelete(((DocumentPeek)gText)->docTE);
- SetRect(&TextRect,(*te)->selRect.left
- ,(*te)->selRect.top,
- (*te)->selRect.left+(goffScreen.portBits.bounds.right -
- goffScreen.portBits.bounds.left),
- (*te)->selRect.top+
- gNormFInfo.ascent+gNormFInfo.descent
- +gNormFInfo.leading);
- SetPort(gText);
- PushClip(TEXT_CLIP);
- ClipRect(&(*te)->viewRect);
- EraseRect(&TextRect);
- PopClip(TEXT_CLIP);
- }
- SetPort(gPredict);
- PushClip(PRED_CLIP);
- SetRect(&Clip,gPredict->portRect.left,gPredict->portRect.top,gPredict->portRect.right-15, gPredict->portRect.bottom-15);
- ClipRect(&Clip);
-
- GetGlobalRect(gPredict,&globalRect);
- if(CheckBoundsOffscreen(((OffscreenPeek)gPredict)->fBackHandle,&globalRect, &drawNeeded)) debugstr("No Memory in AdjustCurPred")/* Handle Memerr? */;
- if(drawNeeded){
- BeginOffscreenDrawing(((OffscreenPeek)gPredict)->fBackHandle,gPredict);
- EraseRect(&gPredict->portRect);
- ReDrawPredictions();
- EndOffscreenDrawing(((OffscreenPeek)gPredict)->fBackHandle);
- }
- backMap = GetMap(((OffscreenPeek)gPredict)->fBackHandle);
- selectMap = GetMap(((OffscreenPeek)gPredict)->fSelectHandle);
-
- if(backMap){
- ForeColor(blackColor);
- BackColor(whiteColor);
- if(selectMap){
- CopyBits(backMap, &gPredict->portBits, &gPredict->portRect, &gPredict->portRect, srcCopy, nil);
- }
- ValidRectOffscreen(((OffscreenPeek)gPredict)->fBackHandle, nil, &gPredict->portRect);
- }
- PopClip(PRED_CLIP);
- }